package com.mall.service.marketing.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.SmsCouponProductCategoryRelation;
import com.mall.model.domain.SmsFlashPromotionProductRelation;
import com.mall.service.marketing.service.FlashProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName FlashProductRelationController
 * @Description 优惠卷的产品关系
 * @Author Young
 * @Date 2023/3/12 10:01
 * @Version 1.0
 */
@RestController
@RequestMapping("/flashProductRelation")
public class FlashProductRelationController {

    @Autowired
    private FlashProductRelationService flashProductRelationService;

    /**
     * 批量选择商品添加关联
     * @param sfppr
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsFlashPromotionProductRelation> sfppr){
        flashProductRelationService.create(sfppr);
        return CommonResult.success("1","操作成功");
    }

    /**
     * 删除关联
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        flashProductRelationService.delete(id);
        return CommonResult.success("1","删除成功");
    }

    /**
     * 分页查询不同场次关联及商品信息
     * @param flashPromotionId
     * @param flashPromotionSessionId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(Integer flashPromotionId, Integer flashPromotionSessionId,Integer pageNum,Integer pageSize){
        CommonPage page = flashProductRelationService.myList(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);
        return CommonResult.success(page,"查询成功");
    }

    /**
     * 修改关联信息
     * @return
     */
    @PostMapping("update/{id}")
    public CommonResult update(@PathVariable Integer id,@RequestBody SmsFlashPromotionProductRelation sfppr){
        flashProductRelationService.myUpdate(id,sfppr);
        return CommonResult.success("1","修改成功");
    }

    /**
     * 获取管理商品促销信息
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult get(@PathVariable Integer id){
        SmsFlashPromotionProductRelation sfppr =flashProductRelationService.get(id);
        return CommonResult.success(sfppr,"获取成功");
    }
}
